﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DictionaryController : ControllerBase
    {
        private readonly WmssystemContext myDbContext;
        private readonly Sys_DictionaryS Sys_DictionaryS;

        public DictionaryController(WmssystemContext myDbContext, Sys_DictionaryS Sys_DictionaryS)
        {
            this.myDbContext = myDbContext;
            this.Sys_DictionaryS = Sys_DictionaryS;
        }
        /// <summary>
        /// 数据字典分页模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<Sys_Dictionary>> FenYe(int pageSize, int currentPage, string Name = null, string Type = null, bool? Status = null)
        {
            return await Sys_DictionaryS.FenYe(pageSize, currentPage, Name, Type, Status);
        }
        /// <summary>
        /// 数据字典添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(Sys_Dictionary dicAdd)
        {
            // 为实体的属性赋值
            dicAdd.D_IsDelete = true;
            dicAdd.D_Date = DateTime.Now;

            // 调用服务层的方法执行添加操作
            return await Sys_DictionaryS.Add(dicAdd);
        }
        /// <summary>
        /// 数据字典修改
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult<int>> Update(Sys_Dictionary dicUpd)
        {
            return await Sys_DictionaryS.Upd(dicUpd);
        }
        /// <summary>
        /// 数据字典逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, bool isDeleted)
        {
            return await Sys_DictionaryS.UpdIsDelete(id, isDeleted);
        }
    }
}
